#!/bin/sh

set -e

start=`date +%s`
echo "Start build apk......"

# clean target
rm -rf target
mkdir target
./gradlew clean

channel="happytest"
if [ $# != 1 ] ; then
  echo "default channel is $channel"
else
  channel=$1
fi
compileChannel=`echo $channel |sed 's/^../\u&/'`
task=assemble$compileChannel
echo "build $task"

# build aar
echo "build aar"
./gradlew $task
echo "merge release aar"
./gradlew mergeAar -PbuildType=release -Pchannel=$channel
cp sdk/build/outputs/aar/*_release.aar target/

# build jar
echo "build jar"
./gradlew proguardJar -x lint -Pchannel=$channel
cp sdk/build/libs/*release* target/

end=`date +%s`

cost=$(( $end - $start ))
echo "Done. Total costs $cost seconds."
